package com.example.router

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.example.base.app.conts.BaseConst
import com.example.base.app.path.RouterPath
import com.tencent.mmkv.MMKV

/**
 * 页面路由参数拦截器
 */
@Interceptor(priority = 4, name = "路由参数拦截器")
class RouterParamsInterceptor:IInterceptor {
    private lateinit var mContext:Context

    override fun init(context: Context?) {
        context?.let {
            mContext = it
        }
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //读取Token
        val traceId = MMKV.defaultMMKV().decodeString("traceId", "")
        if(!traceId.isNullOrEmpty()){
            postcard?.withString("traceId",traceId)
        }else{
            callback?.onContinue(postcard)
        }
    }
}